constants
Variables Timm Mar10 Sandbox Revised

Defining Constants

Problem
=======

How to pre-define a set of standard global constants.

Solution
========

Write a function that defines all the constants.

Code
====

 function constants() {
   Inf    = 10^32;
   Ninf   = -1 * Inf;
   Ee     = 848456353 / 312129649; # 2.71...
   Pi     = 428224593349304 / 136308121570117; # 3.14...
   good to 29 digits
   Sp     = " ";
   Q      = "\"";
   White  = "^[ \t\n\r]*$";
   Number="^[+-]?([0-9]+[.]?[0-9]*|[.][0-9]+)([eE][+-]?[0-9]+)?$"
   _      = SUBSEP; 
 }
 

Discussion
==========

Globals are bad and _N-1_ globals is always better than _N_.  The above code drops concepts into
a global space and imposes constraints on every function in the AWK cookbook. So this above list
should be kept to a minimum.

Note that:
+ Resetting the random number seed should be separate to this process since that gets called  any number of ways.  
+ The above constants are _not_ defined unless this code is called. So if you do not like these settings, write another _myConstants_ function.

All the above are self-explanatory,  except perhaps the "_\__" constant.
This is a convenient shorthand when processing arrays with multiple keys. Suppose we are using  some multi-dimensional
and the number of (e.g.):

+ _cars,green_ is stored at _a\[cars,green,0\]_
+ _colors_     is stored at _a\[colors,0\]_

With the "_\__" constant, the following code can find the number of green
cars and colors, no matter how what is the dimensionality of the keys:
			      
  function howMany (key,a) { return a[key \_ 0] ]

Author
======

Tim Menzies

